/*
 * Javlov - a Java toolkit for reinforcement learning with multi-agent support.
 * 
 * Copyright (c) 2009 Matthijs Snel
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.javlov;

import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("unchecked")
public class TransitionModel {

	protected Map<State, Map<State, Double>[]> model;
	protected int numactions;
	
	public TransitionModel(int states, int actions) {
		numactions = actions;
		model = new HashMap<State, Map<State, Double>[]>(states*2, 0.5f);
	}
	
	public void addEntry(State s, Action a, State sprime, double transitionprob) {
		Map<State, Double>[] entry = model.get(s);
		if ( entry == null ) {
			entry = initializeNewEntry();
			model.put(s, entry);
		}
		entry[a.getID()].put(sprime, transitionprob);
	}
	
	protected Map<State, Double>[] initializeNewEntry() {
		Map[] entry = new HashMap[numactions];
		for ( int i = 0; i < numactions; i++ )
			entry[i] = new HashMap<State, Double>(16, 0.5f);
		return entry;
	}
}
